home *** CD-ROM | disk | FTP | other *** search
/ Chip 2006 July / CHIP 2006-07.2.iso / program / web_gelistirme / easyphp1-7_setup.exe / {app} / phpmyadmin / tbl_change.php < prev    next >
Encoding:
PHP Script  |  2003-09-07  |  33.2 KB  |  774 lines

  1. <?php
  2. /* $Id: tbl_change.php,v 1.157.2.1 2003/08/27 14:20:11 rabus Exp $ */
  3. // vim: expandtab sw=4 ts=4 sts=4:
  4.  
  5.  
  6. /**
  7.  * Get the variables sent or posted to this script and displays the header
  8.  */
  9. require('./libraries/grab_globals.lib.php');
  10. $js_to_run = 'tbl_change.js';
  11. require('./header.inc.php');
  12. require('./libraries/relation.lib.php'); // foreign keys
  13.  
  14.  
  15. /**
  16.  * Displays the query submitted and its result
  17.  */
  18. if (!empty($disp_message)) {
  19.     if (isset($goto)) {
  20.         $goto_cpy      = $goto;
  21.         $goto          = 'tbl_properties.php?'
  22.                        . PMA_generate_common_url($db, $table)
  23.                        . '&$show_query=1'
  24.                        . '&sql_query=' . (isset($disp_query) ? urlencode($disp_query) : '');
  25.     } else {
  26.         $show_query = '1';
  27.     }
  28.     if (isset($sql_query)) {
  29.         $sql_query_cpy = $sql_query;
  30.         unset($sql_query);
  31.     }
  32.     if (isset($disp_query)) {
  33.         $sql_query     = $disp_query;
  34.     }
  35.     PMA_showMessage($disp_message);
  36.     if (isset($goto_cpy)) {
  37.         $goto          = $goto_cpy;
  38.         unset($goto_cpy);
  39.     }
  40.     if (isset($sql_query_cpy)) {
  41.         $sql_query     = $sql_query_cpy;
  42.         unset($sql_query_cpy);
  43.     }
  44. }
  45.  
  46.  
  47. /**
  48.  * Defines the url to return to in case of error in a sql statement
  49.  */
  50. if (!isset($goto)) {
  51.     $goto    = 'db_details.php';
  52. }
  53. if (!ereg('^(db_details|tbl_properties|tbl_select)', $goto)) {
  54.     $err_url = $goto . "?" . PMA_generate_common_url($db) . "&sql_query=" . urlencode($sql_query);
  55. } else {
  56.     $err_url = $goto . '?'
  57.              . PMA_generate_common_url($db)
  58.              . ((ereg('^(tbl_properties|tbl_select)', $goto)) ? '&table=' . urlencode($table) : '');
  59. }
  60.  
  61.  
  62. /**
  63.  * Ensures db and table are valid, else moves to the "parent" script
  64.  */
  65. require('./libraries/db_table_exists.lib.php');
  66.  
  67.  
  68. /**
  69.  * Sets parameters for links and displays top menu
  70.  */
  71. $url_query = PMA_generate_common_url($db, $table)
  72.            . '&goto=tbl_properties.php';
  73.  
  74. require('./tbl_properties_table_info.php');
  75. echo '<br />';
  76.  
  77.  
  78. /**
  79.  * Get the list of the fields of the current table
  80.  */
  81. PMA_mysql_select_db($db);
  82. $table_def = PMA_mysql_query('SHOW FIELDS FROM ' . PMA_backquote($table));
  83. if (isset($primary_key)) {
  84.     $local_query = 'SELECT * FROM ' . PMA_backquote($table) . ' WHERE ' . $primary_key;
  85.     $result      = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url);
  86.     $row         = PMA_mysql_fetch_array($result);
  87.  
  88.     // No row returned
  89.     if (!$row) {
  90.         unset($row);
  91.         unset($primary_key);
  92.         $goto_cpy          = $goto;
  93.         $goto              = 'tbl_properties.php?'
  94.                            . PMA_generate_common_url($db, $table)
  95.                            . '&$show_query=1'
  96.                            . '&sql_query=' . urlencode($local_query);
  97.         if (isset($sql_query)) {
  98.             $sql_query_cpy = $sql_query;
  99.             unset($sql_query);
  100.         }
  101.         $sql_query         = $local_query;
  102.         PMA_showMessage($strEmptyResultSet);
  103.         $goto              = $goto_cpy;
  104.         unset($goto_cpy);
  105.         if (isset($sql_query_cpy)) {
  106.             $sql_query    = $sql_query_cpy;
  107.             unset($sql_query_cpy);
  108.         }
  109.     } // end if (no record returned)
  110. }
  111. else
  112. {
  113.     $local_query = 'SELECT * FROM ' . PMA_backquote($table) . ' LIMIT 1';
  114.     $result      = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url);
  115.     unset($row);
  116. }
  117.  
  118. // <markus@noga.de>
  119. // retrieve keys into foreign fields, if any
  120. $cfgRelation = PMA_getRelationsParam();
  121. $foreigners  = ($cfgRelation['relwork'] ? PMA_getForeigners($db, $table) : FALSE);
  122.  
  123.  
  124. /**
  125.  * Displays the form
  126.  */
  127. // loic1: autocomplete feature of IE kills the "onchange" event handler and it
  128. //        must be replaced by the "onpropertychange" one in this case
  129. $chg_evt_handler = (PMA_USR_BROWSER_AGENT == 'IE' && PMA_USR_BROWSER_VER >= 5)
  130.                  ? 'onpropertychange'
  131.                  : 'onchange';
  132. // Had to put the URI because when hosted on an https server,
  133. // some browsers send wrongly this form to the http server.
  134. ?>
  135.  
  136. <?php if ($cfg['CtrlArrowsMoving']) { ?>
  137. <!-- Set on key handler for moving using by Ctrl+arrows -->
  138. <script type="text/javascript" language="javascript">
  139. <!--
  140. document.onkeydown = onKeyDownArrowsHandler;
  141. // -->
  142. </script>
  143. <?php } ?>
  144.  
  145. <!-- Change table properties form -->
  146. <form method="post" action="tbl_replace.php" name="insertForm" <?php if ($is_upload) echo ' enctype="multipart/form-data"'; ?>>
  147.     <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
  148.     <input type="hidden" name="goto" value="<?php echo $goto; ?>" />
  149.     <input type="hidden" name="pos" value="<?php echo isset($pos) ? $pos : 0; ?>" />
  150.     <input type="hidden" name="session_max_rows" value="<?php echo isset($session_max_rows) ? $session_max_rows : ''; ?>" />
  151.     <input type="hidden" name="disp_direction" value="<?php echo isset($disp_direction) ? $disp_direction : ''; ?>" />
  152.     <input type="hidden" name="repeat_cells" value="<?php echo isset($repeat_cells) ? $repeat_cells : ''; ?>" />
  153.     <input type="hidden" name="dontlimitchars" value="<?php echo (isset($dontlimitchars) ? $dontlimitchars : 0); ?>" />
  154.     <input type="hidden" name="err_url" value="<?php echo urlencode($err_url); ?>" />
  155.     <input type="hidden" name="sql_query" value="<?php echo isset($sql_query) ? urlencode($sql_query) : ''; ?>" />
  156. <?php
  157. if (isset($primary_key)) {
  158.     ?>
  159.     <input type="hidden" name="primary_key" value="<?php echo urlencode($primary_key); ?>" />
  160.     <?php
  161. }
  162. echo "\n";
  163. ?>
  164.  
  165.     <table border="<?php echo $cfg['Border']; ?>">
  166.     <tr>
  167.         <th><?php echo $strField; ?></th>
  168.         <th><?php echo $strType; ?></th>
  169. <?php
  170. if ($cfg['ShowFunctionFields']) {
  171.     echo '        <th>' . $strFunction . '</th>' . "\n";
  172. }
  173. ?>
  174.         <th><?php echo $strNull; ?></th>
  175.         <th><?php echo $strValue; ?></th>
  176.     </tr>
  177.  
  178. <?php
  179. if ($cfg['PropertiesIconic'] == true) {
  180.     // We need to copy the value or else the == 'both' check will always return true
  181.     $propicon = (string)$cfg['PropertiesIconic'];
  182.  
  183.     if ($propicon == 'both') {
  184.         $iconic_spacer = '<nobr>';
  185.     } else {
  186.         $iconic_spacer = '';
  187.     }
  188.  
  189.     $titles['Browse']     = $iconic_spacer . '<img width="12" height="13" src="images/button_browse.png" alt="' . $strBrowseForeignValues . '" title="' . $strBrowseForeignValues . '" border="0" />';
  190.  
  191.     if ($propicon == 'both') {
  192.         $titles['Browse']        .= ' ' . $strBrowseForeignValues . '</nobr>';
  193.     }
  194. } else {
  195.     $titles['Browse']        = $strBrowseForeignValues;
  196. }
  197.  
  198. // Set if we passed the first timestamp field
  199. $timestamp_seen = 0;
  200. $fields_cnt     = mysql_num_rows($table_def);
  201.  
  202. // Set a flag here because the 'if' would not be valid in the loop
  203. // if we set a value in some field
  204. $insert_mode = (!isset($row) ? TRUE : FALSE);
  205.  
  206. for ($i = 0; $i < $fields_cnt; $i++) {
  207.     // Display the submit button after every 15 lines --swix
  208.     // (wanted to use an <a href="#bottom"> and <a name> instead,
  209.     // but it didn't worked because of the <base href>)
  210.  
  211.     if ((($i % 15) == 0) && ($i != 0)) {
  212.         ?>
  213.     <tr>
  214.         <th colspan="5" align="right">
  215.             <input type="submit" value="<?php echo $strGo; ?>" /> 
  216.         </th>
  217.     </tr>
  218.         <?php
  219.     } // end if
  220.     echo "\n";
  221.  
  222.     $row_table_def   = PMA_mysql_fetch_array($table_def);
  223.     $row_table_def['True_Type'] = ereg_replace('\\(.*', '', $row_table_def['Type']);
  224.     $field           = $row_table_def['Field'];
  225.  
  226.     // garvin: possible workaround. If current field is numerical, do not try to
  227.     //  access the result-array with its 'associative' key but with its numerical
  228.     //  represantation.
  229.     if ((PMA_PHP_INT_VERSION > 40000 && is_numeric($field)) || eregi('^[0-9]*$', $field)) {
  230.         $rowfield = $i;
  231.     } else {
  232.         $rowfield = $field;
  233.     }
  234.  
  235.     // loic1: current date should not be set as default if the field is NULL
  236.     //        for the current row
  237.     // lem9:  but do not put here the current datetime if there is a default
  238.     //        value (the real default value will be set in the
  239.     //        Default value logic below)
  240.     if ($row_table_def['Type'] == 'datetime'
  241.         && (!isset($row_table_def['Default']))) {
  242.         // INSERT case
  243.         if ($insert_mode) {
  244.             $row[$rowfield] = date('Y-m-d H:i:s', time());
  245.         }
  246.         // UPDATE case with an empty and not NULL value under PHP4
  247.         else if (empty($row[$rowfield]) && function_exists('is_null')) {
  248.             $row[$rowfield] = (is_null($row[$rowfield]) ? $row[$rowfield] : date('Y-m-d H:i:s', time()));
  249.         }
  250.         // UPDATE case with an empty value under PHP3
  251.         else if (empty($row[$rowfield])) {
  252.             $row[$rowfield] = date('Y-m-d H:i:s', time());
  253.         } // end if... else if... else if...
  254.     }
  255.     $len             = (eregi('float|double', $row_table_def['Type']))
  256.                      ? 100
  257.                      : @mysql_field_len($result, $i);
  258.     $first_timestamp = 0;
  259.  
  260.     $bgcolor = ($i % 2) ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo'];
  261.     ?>
  262.     <tr>
  263.         <td <?php echo ($cfg['LongtextDoubleTextarea'] && strstr($row_table_def['True_Type'], 'longtext') ? 'rowspan="2"' : ''); ?> align="center" bgcolor="<?php echo $bgcolor; ?>"><?php echo htmlspecialchars($field); ?></td>
  264.     <?php
  265.     echo "\n";
  266.  
  267.     // The type column
  268.     $is_binary                  = eregi(' binary', $row_table_def['Type']);
  269.     $is_blob                    = eregi('blob', $row_table_def['Type']);
  270.     $is_char                    = eregi('char', $row_table_def['Type']);
  271.     switch ($row_table_def['True_Type']) {
  272.         case 'set':
  273.             $type         = 'set';
  274.             $type_nowrap  = '';
  275.             break;
  276.         case 'enum':
  277.             $type         = 'enum';
  278.             $type_nowrap  = '';
  279.             break;
  280.         case 'timestamp':
  281.             if (!$timestamp_seen) {   // can only occur once per table
  282.                 $timestamp_seen  = 1;
  283.                 $first_timestamp = 1;
  284.             }
  285.             $type         = $row_table_def['Type'];
  286.             $type_nowrap  = ' nowrap="nowrap"';
  287.             break;
  288.  
  289.         default:
  290.             $type         = $row_table_def['Type'];
  291.             $type_nowrap  = ' nowrap="nowrap"';
  292.             break;
  293.     }
  294.     ?>
  295.         <td align="center" bgcolor="<?php echo $bgcolor; ?>"<?php echo $type_nowrap; ?>>
  296.             <?php echo $type; ?>
  297.         </td>
  298.     <?php
  299.     echo "\n";
  300.  
  301.     // Prepares the field value
  302.     if (isset($row)) {
  303.         // loic1: null field value
  304.         if (!isset($row[$rowfield])) {
  305.             $row[$rowfield]   = 'NULL';
  306.             $special_chars = '';
  307.             $data          = $row[$rowfield];
  308.         } else {
  309.             // loic1: special binary "characters"
  310.             if ($is_binary || $is_blob) {
  311.                 $row[$rowfield] = str_replace("\x00", '\0', $row[$rowfield]);
  312.                 $row[$rowfield] = str_replace("\x08", '\b', $row[$rowfield]);
  313.                 $row[$rowfield] = str_replace("\x0a", '\n', $row[$rowfield]);
  314.                 $row[$rowfield] = str_replace("\x0d", '\r', $row[$rowfield]);
  315.                 $row[$rowfield] = str_replace("\x1a", '\Z', $row[$rowfield]);
  316.             } // end if
  317.             $special_chars   = htmlspecialchars($row[$rowfield]);
  318.             $data            = $row[$rowfield];
  319.         } // end if... else...
  320.         // loic1: if a timestamp field value is not included in an update
  321.         //        statement MySQL auto-update it to the current timestamp
  322.         $backup_field  = ($row_table_def['True_Type'] == 'timestamp')
  323.                        ? ''
  324.                        : '<input type="hidden" name="fields_prev[' . urlencode($field) . ']" value="' . urlencode($row[$rowfield]) . '" />';
  325.     } else {
  326.         // loic1: display default values
  327.         if (!isset($row_table_def['Default'])) {
  328.             $row_table_def['Default'] = '';
  329.             $data                     = 'NULL';
  330.         } else {
  331.             $data                     = $row_table_def['Default'];
  332.         }
  333.         $special_chars = htmlspecialchars($row_table_def['Default']);
  334.         $backup_field  = '';
  335.     }
  336.  
  337.     // The function column
  338.     // -------------------
  339.     // Change by Bernard M. Piller <bernard@bmpsystems.com>
  340.     // We don't want binary data to be destroyed
  341.     // Note: from the MySQL manual: "BINARY doesn't affect how the column is
  342.     //       stored or retrieved" so it does not mean that the contents is
  343.     //       binary
  344.     if ($cfg['ShowFunctionFields']) {
  345.         if (($cfg['ProtectBinary'] && $is_blob)
  346.             || ($cfg['ProtectBinary'] == 'all' && $is_binary)) {
  347.             echo '        <td align="center" bgcolor="'. $bgcolor . '">' . $strBinary . '</td>' . "\n";
  348.         } else if (strstr($row_table_def['True_Type'], 'enum') || strstr($row_table_def['True_Type'], 'set')) {
  349.             echo '        <td align="center" bgcolor="'. $bgcolor . '">--</td>' . "\n";
  350.         } else {
  351.             ?>
  352.         <td bgcolor="<?php echo $bgcolor; ?>">
  353.             <select name="funcs[<?php echo urlencode($field); ?>]" <?php echo $chg_evt_handler; ?>="return unNullify('<?php echo urlencode($field); ?>')" tabindex="<?php echo ($fields_cnt + $i + 1); ?>" id="field_<?php echo $i; ?>_1">
  354.                 <option></option>
  355.             <?php
  356.             echo "\n";
  357.             $selected     = '';
  358.  
  359.             // garvin: Find the current type in the RestrictColumnTypes. Will result in 'FUNC_CHAR'
  360.             // or something similar. Then directly look up the entry in the RestrictFunctions array,
  361.             // which will then reveal the available dropdown options
  362.             if (isset($cfg['RestrictFunctions']) && isset($cfg['RestrictColumnTypes']) && isset($cfg['RestrictColumnTypes'][strtoupper($row_table_def['True_Type'])]) && isset($cfg['RestrictFunctions'][$cfg['RestrictColumnTypes'][strtoupper($row_table_def['True_Type'])]])) {
  363.                 $dropdown = $cfg['RestrictFunctions'][$cfg['RestrictColumnTypes'][strtoupper($row_table_def['True_Type'])]];
  364.             } else {
  365.                 $dropdown = array();
  366.             }
  367.  
  368.             $dropdown_built = array();
  369.             $op_spacing_needed = FALSE;
  370.  
  371.             // garvin: loop on the dropdown array and print all available options for that field.
  372.             for ($j = 0; $j < count($dropdown); $j++) {
  373.                 // for default function = NOW() on first timestamp field
  374.                 // -- swix/18jul01
  375.                 $selected = ($first_timestamp && $dropdown[$j] == 'NOW')
  376.                           ? ' selected="selected"'
  377.                           : '';
  378.                 echo '                ';
  379.                 echo '<option' . $selected . '>' . $dropdown[$j] . '</option>' . "\n";
  380.                 $dropdown_built[$dropdown[$j]] = 'TRUE';
  381.                 $op_spacing_needed = TRUE;
  382.             }
  383.  
  384.             // garvin: For compatibility's sake, do not let out all other functions. Instead
  385.             // print a seperator (blank) and then show ALL functions which weren't shown
  386.             // yet.
  387.             for ($j = 0; $j < count($cfg['Functions']); $j++) {
  388.                 if (!isset($dropdown_built[$cfg['Functions'][$j]]) || $dropdown_built[$cfg['Functions'][$j]] != 'TRUE') {
  389.                     // for default function = NOW() on first timestamp field
  390.                     // -- swix/18jul01
  391.                     $selected = ($first_timestamp && $cfg['Functions'][$j] == 'NOW')
  392.                               ? ' selected="selected"'
  393.                               : '';
  394.                     if ($op_spacing_needed == TRUE) {
  395.                         echo '                ';
  396.                         echo '<option value="">--------</option>' . "\n";
  397.                         $op_spacing_needed = FALSE;
  398.                     }
  399.  
  400.                     echo '                ';
  401.                     echo '<option' . $selected . '>' . $cfg['Functions'][$j] . '</option>' . "\n";
  402.                 }
  403.             } // end for
  404.             unset($selected);
  405.             ?>
  406.             </select>
  407.         </td>
  408.             <?php
  409.         }
  410.     } // end if ($cfg['ShowFunctionFields'])
  411.     echo "\n";
  412.  
  413.     // The null column
  414.     // ---------------
  415.     echo '        <td bgcolor="' . $bgcolor . '">' . "\n";
  416.     if (!(($cfg['ProtectBinary'] && $is_blob) || ($cfg['ProtectBinary'] == 'all' && $is_binary))
  417.         && $row_table_def['Null'] == 'YES') {
  418.         echo '            <input type="checkbox" tabindex="' . ((2 * $fields_cnt) + $i + 1) . '"'
  419.              . ' name="fields_null[' . urlencode($field) . ']"';
  420.         if ($data == 'NULL' && !$first_timestamp) {
  421.             echo ' checked="checked"';
  422.         }
  423.         echo ' id="field_' . $i . '_2"';
  424.         $onclick         = ' onclick="if (this.checked) {nullify(';
  425.         if (strstr($row_table_def['True_Type'], 'enum')) {
  426.             if (strlen($row_table_def['Type']) > 20) {
  427.                 $onclick .= '1, ';
  428.             } else {
  429.                 $onclick .= '2, ';
  430.             }
  431.         } else if (strstr($row_table_def['True_Type'], 'set')) {
  432.             $onclick     .= '3, ';
  433.         } else if ($foreigners && isset($foreigners[$field])) {
  434.             $onclick     .= '4, ';
  435.         } else {
  436.             $onclick     .= '5, ';
  437.         }
  438.         $onclick         .= '\'' . urlencode($field) . '\', \'' . md5($field) . '\'); this.checked = true}; return true" />' . "\n";
  439.         echo $onclick;
  440.     } else {
  441.         echo '             ' . "\n";
  442.     }
  443.     echo '        </td>' . "\n";
  444.  
  445.     // The value column (depends on type)
  446.     // ----------------
  447.  
  448.     include('./libraries/get_foreign.lib.php');
  449.  
  450.     if (isset($foreign_link) && $foreign_link == true) {
  451.         ?>
  452.         <td bgcolor="<?php echo $bgcolor; ?>">
  453.         <?php echo $backup_field . "\n"; ?>
  454.         <input type="hidden" name="fields_type[<?php echo urlencode($field); ?>]" value="foreign" />
  455.         <input type="hidden" name="fields[<?php echo urlencode($field); ?>]" value="" id="field_<?php echo $i; ?>_1" />
  456.         <input type="text"   name="field_<?php echo md5($field); ?>[]" class="textfield" <?php echo $chg_evt_handler; ?>="return unNullify('<?php echo urlencode($field); ?>')" tabindex="<?php echo ($i + 1); ?>" id="field_<?php echo $i; ?>_3" value="<?php echo htmlspecialchars($data); ?>" />
  457.         <script type="text/javascript" language="javascript">
  458.             document.writeln('<a target="_blank" onclick="window.open(this.href, \'foreigners\', \'width=640,height=240,scrollbars=yes\'); return false" href="browse_foreigners.php?<?php echo PMA_generate_common_url($db, $table); ?>&field=<?php echo urlencode($field); ?>"><?php echo str_replace("'", "\'", $titles['Browse']); ?></a>');
  459.         </script>
  460.         </td>
  461.         <?php
  462.     } else if (isset($disp) && $disp) {
  463.         ?>
  464.         <td bgcolor="<?php echo $bgcolor; ?>">
  465.         <?php echo $backup_field . "\n"; ?>
  466.         <input type="hidden" name="fields_type[<?php echo urlencode($field); ?>]" value="foreign" />
  467.         <input type="hidden" name="fields[<?php echo urlencode($field); ?>]" value="" id="field_<?php echo $i; ?>_1" />
  468.         <select name="field_<?php echo md5($field); ?>[]" <?php echo $chg_evt_handler; ?>="return unNullify('<?php echo urlencode($field); ?>')" tabindex="<?php echo ($i + 1); ?>" id="field_<?php echo $i; ?>_3">
  469.             <?php echo PMA_foreignDropdown($disp, $foreign_field, $foreign_display, $data, 100); ?>
  470.         </select>
  471.         </td>
  472.         <?php
  473.         unset($disp);
  474.     }
  475.     else if ($cfg['LongtextDoubleTextarea'] && strstr($type, 'longtext')) {
  476.         ?>
  477.         <td bgcolor="<?php echo $bgcolor; ?>"> </td>
  478.     </tr>
  479.     <tr>
  480.         <td colspan="4" align="right" bgcolor="<?php echo $bgcolor; ?>">
  481.             <?php echo $backup_field . "\n"; ?>
  482.             <textarea name="fields[<?php echo urlencode($field); ?>]" rows="<?php echo ($cfg['TextareaRows']*2); ?>" cols="<?php echo ($cfg['TextareaCols']*2); ?>" wrap="virtual" dir="<?php echo $text_dir; ?>" id="field_<?php echo $i; ?>_3"
  483.                 <?php echo $chg_evt_handler; ?>="return unNullify('<?php echo urlencode($field); ?>')" tabindex="<?php echo ($i + 1); ?>"><?php echo $special_chars; ?></textarea>
  484.         </td>
  485.       <?php
  486.     }
  487.     else if (strstr($type, 'text')) {
  488.         ?>
  489.         <td bgcolor="<?php echo $bgcolor; ?>">
  490.             <?php echo $backup_field . "\n"; ?>
  491.             <textarea name="fields[<?php echo urlencode($field); ?>]" rows="<?php echo $cfg['TextareaRows']; ?>" cols="<?php echo $cfg['TextareaCols']; ?>" wrap="virtual" dir="<?php echo $text_dir; ?>" id="field_<?php echo $i; ?>_3"
  492.                 <?php echo $chg_evt_handler; ?>="return unNullify('<?php echo urlencode($field); ?>')" tabindex="<?php echo ($i + 1); ?>"><?php echo $special_chars; ?></textarea>
  493.         </td>
  494.         <?php
  495.         echo "\n";
  496.         if (strlen($special_chars) > 32000) {
  497.             echo '        <td bgcolor="' . $bgcolor . '">' . $strTextAreaLength . '</td>' . "\n";
  498.         }
  499.     }
  500.     else if ($type == 'enum') {
  501.         $enum        = PMA_getEnumSetOptions($row_table_def['Type']);
  502.         $enum_cnt    = count($enum);
  503.         ?>
  504.         <td bgcolor="<?php echo $bgcolor; ?>">
  505.             <input type="hidden" name="fields_type[<?php echo urlencode($field); ?>]" value="enum" />
  506.             <input type="hidden" name="fields[<?php echo urlencode($field); ?>]" value="" />
  507.         <?php
  508.         echo "\n" . '            ' . $backup_field;
  509.  
  510.         // show dropdown or radio depend on length
  511.         if (strlen($row_table_def['Type']) > 20) {
  512.             echo "\n";
  513.             ?>
  514.             <select name="field_<?php echo md5($field); ?>[]" <?php echo $chg_evt_handler; ?>="return unNullify('<?php echo urlencode($field); ?>')" tabindex="<?php echo ($i + 1); ?>" id="field_<?php echo $i; ?>_3">
  515.                 <option value=""></option>
  516.             <?php
  517.             echo "\n";
  518.  
  519.             for ($j = 0; $j < $enum_cnt; $j++) {
  520.                 // Removes automatic MySQL escape format
  521.                 $enum_atom = str_replace('\'\'', '\'', str_replace('\\\\', '\\', $enum[$j]));
  522.                 echo '                ';
  523.                 echo '<option value="' . htmlspecialchars($enum_atom) . '"';
  524.                 if ($data == $enum_atom
  525.                     || ($data == '' && (!isset($primary_key) || $row_table_def['Null'] != 'YES')
  526.                         && isset($row_table_def['Default']) && $enum_atom == $row_table_def['Default'])) {
  527.                     echo ' selected="selected"';
  528.                 }
  529.                 echo '>' . htmlspecialchars($enum_atom) . '</option>' . "\n";
  530.             } // end for
  531.  
  532.             ?>
  533.             </select>
  534.             <?php
  535.         } // end if
  536.         else {
  537.             echo "\n";
  538.             for ($j = 0; $j < $enum_cnt; $j++) {
  539.                 // Removes automatic MySQL escape format
  540.                 $enum_atom = str_replace('\'\'', '\'', str_replace('\\\\', '\\', $enum[$j]));
  541.                 echo '            ';
  542.                 echo '<input type="radio" name="field_' . md5($field) . '[]" value="' . urlencode($enum_atom) . '" id="field_' . $i . '_3_'  . $j . '" onclick="if (typeof(document.forms[\'insertForm\'].elements[\'fields_null[' . urlencode($field) . ']\']) != \'undefined\') {document.forms[\'insertForm\'].elements[\'fields_null[' . urlencode($field) .']\'].checked = false}"';
  543.                 if ($data == $enum_atom
  544.                     || ($data == '' && (!isset($primary_key) || $row_table_def['Null'] != 'YES')
  545.                         && isset($row_table_def['Default']) && $enum_atom == $row_table_def['Default'])) {
  546.                     echo ' checked="checked"';
  547.                 }
  548.                 echo 'tabindex="' . ($i + 1) . '" />' . "\n";
  549.                 echo '            <label for="field_' . $i . '_3_' . $j . '">' . htmlspecialchars($enum_atom) . '</label>' . "\n";
  550.             } // end for
  551.  
  552.         } // end else
  553.         echo "\n";
  554.         ?>
  555.         </td>
  556.         <?php
  557.         echo "\n";
  558.     }
  559.     else if ($type == 'set') {
  560.         $set = PMA_getEnumSetOptions($row_table_def['Type']);
  561.  
  562.         if (isset($vset)) {
  563.             unset($vset);
  564.         }
  565.         for ($vals = explode(',', $data); list($t, $k) = each($vals);) {
  566.             $vset[$k] = 1;
  567.         }
  568.         $countset = count($set);
  569.         $size = min(4, $countset);
  570.         ?>
  571.         <td bgcolor="<?php echo $bgcolor; ?>">
  572.             <?php echo $backup_field . "\n"; ?>
  573.             <input type="hidden" name="fields_type[<?php echo urlencode($field); ?>]" value="set" />
  574.             <input type="hidden" name="fields[<?php echo urlencode($field); ?>]" value="" />
  575.             <select name="field_<?php echo md5($field); ?>[]" size="<?php echo $size; ?>" multiple="multiple" <?php echo $chg_evt_handler; ?>="return unNullify('<?php echo urlencode($field); ?>')" tabindex="<?php echo ($i + 1); ?>" id="field_<?php echo $i; ?>_3">
  576.         <?php
  577.         echo "\n";
  578.         for ($j = 0; $j < $countset; $j++) {
  579.             echo '                ';
  580.             echo '<option value="'. htmlspecialchars($set[$j]) . '"';
  581.             if (isset($vset[$set[$j]]) && $vset[$set[$j]]) {
  582.                 echo ' selected="selected"';
  583.             }
  584.             echo '>' . htmlspecialchars($set[$j]) . '</option>' . "\n";
  585.         } // end for
  586.         ?>
  587.             </select>
  588.         </td>
  589.         <?php
  590.     }
  591.     // Change by Bernard M. Piller <bernard@bmpsystems.com>
  592.     // We don't want binary data destroyed
  593.     else if ($is_binary || $is_blob) {
  594.         if (($cfg['ProtectBinary'] && $is_blob)
  595.             || ($cfg['ProtectBinary'] == 'all' && $is_binary)) {
  596.             echo "\n";
  597.             ?>
  598.         <td align="center" bgcolor="<?php echo $bgcolor; ?>">
  599.             <?php
  600.                 echo $strBinaryDoNotEdit;
  601.                 if (isset($data)) {
  602.                     $data_size = PMA_formatByteDown(strlen(stripslashes($data)), 3, 1);
  603.                     echo ' ('. $data_size [0] . ' ' . $data_size[1] . ')';
  604.                     unset($data_size);
  605.                 }
  606.                 echo "\n";
  607.             ?>
  608.             <input type="hidden" name="fields_type[<?php echo urlencode($field); ?>]" value="protected" />
  609.             <input type="hidden" name="fields[<?php echo urlencode($field); ?>]" value="" />
  610.             <?php
  611.         } else if ($is_blob) {
  612.             echo "\n";
  613.             ?>
  614.         <td bgcolor="<?php echo $bgcolor; ?>">
  615.             <?php echo $backup_field . "\n"; ?>
  616.             <textarea name="fields[<?php echo urlencode($field); ?>]" rows="<?php echo $cfg['TextareaRows']; ?>" cols="<?php echo $cfg['TextareaCols']; ?>" wrap="virtual" dir="<?php echo $text_dir; ?>" id="field_<?php echo $i; ?>_3"
  617.                 <?php echo $chg_evt_handler; ?>="return unNullify('<?php echo urlencode($field); ?>')" tabindex="<?php echo ($i + 1); ?>" ><?php echo $special_chars; ?></textarea>
  618.             <?php
  619.  
  620.         } else {
  621.             if ($len < 4) {
  622.                 $fieldsize = $maxlength = 4;
  623.             } else {
  624.                 $fieldsize = (($len > 40) ? 40 : $len);
  625.                 $maxlength = $len;
  626.             }
  627.             echo "\n";
  628.             ?>
  629.         <td bgcolor="<?php echo $bgcolor; ?>">
  630.             <?php echo $backup_field . "\n"; ?>
  631.             <input type="text" name="fields[<?php echo urlencode($field); ?>]" value="<?php echo $special_chars; ?>" size="<?php echo $fieldsize; ?>" maxlength="<?php echo $maxlength; ?>" class="textfield" <?php echo $chg_evt_handler; ?>="return unNullify('<?php echo urlencode($field); ?>')" tabindex="<?php echo ($i + 1); ?>" id="field_<?php echo $i; ?>_3" />
  632.             <?php
  633.         } // end if...elseif...else
  634.  
  635.         // Upload choice (only for BLOBs because the binary
  636.         // attribute does not imply binary contents)
  637.         // (displayed whatever value the ProtectBinary has)
  638.  
  639.         if ($is_upload && $is_blob) {
  640.             echo '<input type="file" name="fields_upload_' . urlencode($field) . '" class="textfield" id="field_' . $i . '_3" />';
  641.         }
  642.  
  643.         if ($cfg['UploadDir'] != '') {
  644.             if ($handle = @opendir($cfg['UploadDir'])) {
  645.                 $is_first = 0;
  646.                 while ($file = @readdir($handle)) {
  647.                     if (is_file($cfg['UploadDir'] . $file) && substr($file, -4) != '.sql') {
  648.                         if ($is_first == 0) {
  649.                             echo "<br />\n";
  650.                             echo '    <i>' . $strOr . '</i>' . ' ' . $strWebServerUploadDirectory . ' :<br />' . "\n";
  651.                             echo '        <select size="1" name="fields_uploadlocal_' . urlencode($field) . '">' . "\n";
  652.                             echo '            <option value="" selected="selected"></option>' . "\n";
  653.                         } // end if (is_first)
  654.                         echo '            <option value="' . htmlspecialchars($file) . '">' . htmlspecialchars($file) . '</option>' . "\n";
  655.                         $is_first++;
  656.                     } // end if (is_file)
  657.                 } // end while
  658.                 if ($is_first > 0) {
  659.                     echo '        </select>' . "\n";
  660.                 } // end if (isfirst > 0)
  661.                 @closedir($handle);
  662.             } else {
  663.                 echo '        <font color="red">' . $strError . '</font><br />' . "\n";
  664.                 echo '        ' . $strWebServerUploadDirectoryError . "\n";
  665.             }
  666.         } // end if (web-server upload directory)
  667.  
  668.         echo '</td>';
  669.  
  670.     } // end else if ( binary or blob)
  671.     else {
  672.         // For char or varchar, respect the maximum length (M); for other
  673.         // types (int or float), the length is not a limit on the values that
  674.         // can be entered, so let's be generous (20) (we could also use the
  675.         // real limits for each numeric type)
  676.         if ($is_char) {
  677.             $fieldsize = (($len > 40) ? 40 : $len);
  678.             $maxlength = $len;
  679.         }
  680.         else {
  681.             $fieldsize = $maxlength = 20;
  682.         } // end if... else...
  683.         echo "\n";
  684.         ?>
  685.         <td bgcolor="<?php echo $bgcolor; ?>">
  686.             <?php echo $backup_field . "\n"; ?>
  687.         <?php
  688.         if ($is_char && isset($cfg['CharEditing']) && ($cfg['CharEditing'] == 'textarea')) {
  689.             echo "\n";
  690.             ?>
  691.             <textarea name="fields[<?php echo urlencode($field); ?>]" rows="<?php echo $cfg['CharTextareaRows']; ?>" cols="<?php echo $cfg['CharTextareaCols']; ?>" wrap="virtual" dir="<?php echo $text_dir; ?>" id="field_<?php echo $i; ?>_3"
  692.                 <?php echo $chg_evt_handler; ?>="return unNullify('<?php echo urlencode($field); ?>')" tabindex="<?php echo ($i + 1); ?>" ><?php echo $special_chars; ?></textarea>
  693.             <?php
  694.         } else {
  695.             echo "\n";
  696.             ?>
  697.             <input type="text" name="fields[<?php echo urlencode($field); ?>]" value="<?php echo $special_chars; ?>" size="<?php echo $fieldsize; ?>" maxlength="<?php echo $maxlength; ?>" class="textfield" <?php echo $chg_evt_handler; ?>="return unNullify('<?php echo urlencode($field); ?>')" tabindex="<?php echo ($i + 1); ?>" id="field_<?php echo $i; ?>_3" />
  698.             <?php
  699.         }
  700.         echo "\n";
  701.         ?>
  702.         </td>
  703.         <?php
  704.     }
  705.     echo "\n";
  706.     ?>
  707.     </tr>
  708.     <?php
  709. echo "\n";
  710. } // end for
  711. ?>
  712.     </table>
  713.     <br />
  714.  
  715.     <table cellpadding="5">
  716.     <tr>
  717.         <td valign="middle" nowrap="nowrap">
  718. <?php
  719. if (isset($primary_key)) {
  720.     ?>
  721.             <input type="radio" name="submit_type" value="<?php echo $strSave; ?>" id="radio_submit_type_save" checked="checked" tabindex="<?php echo ((3 * $fields_cnt) + 1); ?>" /><label for="radio_submit_type_save"><?php echo $strSave; ?></label><br />
  722.                   <?php echo $strOr; ?><br />
  723.             <input type="radio" name="submit_type" value="<?php echo $strInsertAsNewRow; ?>" id="radio_submit_type_insert_as_new_row" tabindex="<?php echo ((3 * $fields_cnt) + 2); ?>" /><label for="radio_submit_type_insert_as_new_row"><?php echo $strInsertAsNewRow; ?></label>
  724.     <?php
  725. } else {
  726.     echo "\n";
  727.     ?>
  728.             <input type="hidden" name="submit_type" value="<?php echo $strInsertAsNewRow; ?>" />
  729.     <?php
  730.     echo '            ' . $strInsertAsNewRow . "\n";
  731. }
  732. echo "\n";
  733.  
  734. // Defines whether "insert a new row after the current insert" should be
  735. // checked or not (keep this choice sticky)
  736. // but do not check both radios, because Netscape 4.8 would display both checked
  737. if (!empty($disp_message)) {
  738.     $checked_after_insert_new_insert = ' checked="checked"';
  739.     $checked_after_insert_back = '';
  740. } else {
  741.     $checked_after_insert_back = ' checked="checked"';
  742.     $checked_after_insert_new_insert = '';
  743. }
  744. ?>
  745.         </td>
  746.         <td valign="middle">
  747.                <b>-- <?php echo $strAnd; ?> --</b>   
  748.         </td>
  749.         <td valign="middle" nowrap="nowrap">
  750.             <input type="radio" name="after_insert" value="back" id="radio_after_insert_back" <?php echo $checked_after_insert_back; ?> tabindex="<?php echo ((3 * $fields_cnt) + 3); ?>" /><label for="radio_after_insert_back"><?php echo $strAfterInsertBack; ?></label><br />
  751.                   <?php echo $strOr; ?><br />
  752.             <input type="radio" name="after_insert" value="new_insert" id="radio_after_insert_new_insert"<?php echo $checked_after_insert_new_insert; ?> tabindex="<?php echo ((3 * $fields_cnt) + 4); ?>" /><label for="radio_after_insert_new_insert"><?php echo $strAfterInsertNewInsert; ?></label>
  753.         </td>
  754.     </tr>
  755.  
  756.     <tr>
  757.         <td colspan="3" align="right" valign="middle">
  758.             <input type="submit" value="<?php echo $strGo; ?>" tabindex="<?php echo ((3 * $fields_cnt) + 5); ?>" />
  759.             <input type="reset" value="<?php echo $strReset; ?>" tabindex="<?php echo ((3 * $fields_cnt) + 6); ?>" />
  760.         </td>
  761.     </tr>
  762.     </table>
  763.  
  764. </form>
  765.  
  766.  
  767. <?php
  768. /**
  769.  * Displays the footer
  770.  */
  771. echo "\n";
  772. require('./footer.inc.php');
  773. ?>
  774.